import { getUnitListAll } from '@/api/collection/unit'
import { getLabelList } from '@/api/energyCompare/energyLibrary'
import { FormSchema } from '@/components/Table'

export const timeDimensionOptions = [
  { label: '月', value: 0, valueFormat: 'YYYY-MM', picker: 'month' },
  { label: '年', value: 1, valueFormat: 'YYYY', picker: 'year' },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: 'dataTypeName',
    label: '指标名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'timeDimension',
    label: '时间维度',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: timeDimensionOptions,
    },
  },
]

export const addFormSchema: FormSchema[] = [
  {
    field: 'dataTypeId',
    label: '指标名称',
    component: 'ApiSelect',
    rules: [{ required: true }],
    componentProps: {
      api: getLabelList,
      labelField: 'name',
      valueField: 'id',
    },
  },
  {
    field: 'dataUnitId',
    label: '指标单位',
    component: 'ApiSelect',
    rules: [{ required: true }],
    componentProps: {
      api: getUnitListAll,
      labelField: 'name',
      valueField: 'id',
    },
  },
  {
    field: 'timeDimension',
    label: '时间维度',
    component: 'Select',
    rules: [{ required: true }],
    componentProps: {
      options: timeDimensionOptions,
    },
  },
  {
    field: 'description',
    label: '指标描述',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入',
      autoSize: { minRows: 3, maxRows: 5 },
    },
  },
]

export const columns = [
  {
    title: '指标名称',
    dataIndex: 'dataTypeName',
  },
  {
    title: '单位',
    dataIndex: 'dataUnitName',
    width: 100,
  },
  {
    title: '时间维度',
    dataIndex: 'timeDimension',
    width: 80,
    customRender: ({ text }) => {
      return timeDimensionOptions.find((item) => item.value === text)?.label
    },
  },
  {
    title: '指标描述',
    dataIndex: 'description',
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
  },
]
